﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MVCPets.Models;

namespace MVCPets.Helpers
{
  public class SessionHelper : SessionHelperBase
  {
    #region Public Property Accessors
    /// <summary>
    /// Add your own properties here to work with objects stored in the session
    /// </summary>
    public static int UserRole
    {
      get { return GetUserRole(); }
      set { SetValue("UserRole", value); }
    }

    public static string StyleSheet
    {
      get
      {
        var tb = new TagBuilder("link");

        tb.Attributes.Add("rel", "stylesheet");
        tb.Attributes.Add("type", "text/css");
        tb.Attributes.Add("href", string.Format("{0}/site.css", StylePath));

        return tb.ToString(TagRenderMode.SelfClosing); 
      }
    }

    public static string StylePath
    {
      get
      {
        return "/Content";
      }
    }
    
    public static Uri BaseUrl
    {
      get
      {
        var tokens = HttpContext.Current.Request.Url.AbsoluteUri.Replace(@"//", @"/").Split('/');

        return new Uri(string.Format(@"{0}//{1}", tokens[0], tokens[1]));
      }
    }
    #endregion

    #region Private Methods
    private static int GetUserRole()
    {
      var ret = int.MaxValue;
      var foo = GetValue<int>("UserRole");

      if (foo > 0) ret = foo;

      return ret;
    }
    #endregion
  }
}
